package com.cdty.chess.controller;

import com.cdty.chess.model.BetCountInfo;
import com.cdty.chess.model.ChessInfo;
import com.cdty.chess.model.OddsInfo;
import com.cdty.chess.service.BetCifService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 开盘和开奖
 */
@RestController
@RequestMapping("/api/v1/betcif")
public class BetCifController {

    @Autowired
    BetCifService service;

    /**
     * 管理员开盘
     *
     */
    @PostMapping("/upBetStart")
    public String upBetStart(@RequestBody BetCountInfo info){

        return service.upBetStart(info);
    }

    /**
     * 管理员开奖
     *
     */
    @RequestMapping("/upBetEnd")
    public String addBetCInfo(@RequestBody BetCountInfo info){

        return service.upBetEnd(info);
    }

    /**
     * 进入房间查询当前对局
     * @param uid 用户id
     * @param type 类型  区分管理员和普通用户
     * @return
     */
    @GetMapping("/queryBetCount")
    public BetCountInfo queryBetCount(@RequestParam(required = false) String uid,
                                        @RequestParam(required = false) Boolean type){

        return service.queryBetCount(uid,type);
    }

    /**
     * 棋子
     * @return
     */
    @RequestMapping("/chessInfo")
    public List<ChessInfo> chessInfo(){
        return service.chessInfo();
    }


    /**
     * 赔率
     * @return
     */
    @GetMapping("/oddsInfo")
    public List<OddsInfo> oddsInfo(@RequestParam(required = false) String type){
        return service.oddsInfo(type);
    }

    /**
     * 修改赔率
     * @return
     */
    @PostMapping("/updateOdds")
    public int updateOdds(@RequestBody OddsInfo info){
        return service.updateOdds(info);
    }

    /**
     * 统计赔付和下注额
     * @return
     */
    @GetMapping("/getbetStic")
    public Map<String,Object> getbetStic(@RequestParam(required = false) LocalDate time,
                                         @RequestParam(required = false) Integer page,
                                         @RequestParam(required = false) Integer size,
                                         @RequestParam(required = false) String uid){
        return service.getbetStic(time,page,size,uid);
    }

    /**
     * 更新分数
     * @return
     */
    @PostMapping("/upScore")
    public String upScore(@RequestParam(required = false) Integer score,@RequestParam(required = false) String id){
        return service.upScore(score,id);
    }
}
